package utils.com;

import java.util.ArrayList;
import java.util.List;

import model.com.VideoInfo;
import android.content.Context;
import android.database.Cursor;
import database.com.DatabaseHelper;

public class DBtoVideoListUtils {
	private Context context;
	private DatabaseHelper databaseHelper;
	private List<VideoInfo> infos = null;
	
	public DBtoVideoListUtils(List<VideoInfo> infos, Context context) {
		super();
		this.context = context;
		this.infos = infos;
	}
	
	public List<VideoInfo> getInfos() {
		return infos;
	}

	public void setInfos(List<VideoInfo> infos) {
		this.infos = infos;
	}
	
	public List<VideoInfo> getVideoList(String sort){
		List<VideoInfo> infos = new ArrayList<VideoInfo>();
		databaseHelper = new DatabaseHelper(context, "resource");
		Cursor cursor;
		if(sort == null){
			cursor = databaseHelper.query("video", "*", null, null, null);
		}
		else{
			cursor = databaseHelper.query("video", "*", "video_sort", sort, null);
		}
		
		cursor.moveToPosition(-1);
	    while(cursor.moveToNext()){
	    	VideoInfo videoInfo = new VideoInfo();
			videoInfo.setVideo_id(cursor.getInt(1));
			videoInfo.setVideo_title(cursor.getString(2));
			videoInfo.setVideo_name(cursor.getString(3));
			videoInfo.setVideo_size(cursor.getInt(4));
			videoInfo.setVideo_playUrl(cursor.getString(5));
			videoInfo.setVideo_downloadUrl(cursor.getString(6));
			videoInfo.setVideo_time(cursor.getString(7));
			videoInfo.setVideo_info(cursor.getString(8));
			videoInfo.setVideo_sort(cursor.getString(9));
			videoInfo.setImage_url(cursor.getString(10));
			videoInfo.setImage_name(cursor.getString(11));
			videoInfo.setImage_size(cursor.getInt(12));
			videoInfo.setVideo_localUrl(cursor.getString(13));
			videoInfo.setImage_localUrl(cursor.getString(14));
			infos.add(videoInfo);
	    }
      	cursor.close();
		return infos;
	}
}
